const jwt = require("jsonwebtoken");
const configuration = require("../utils/configuration");
const { expiresIn, secret } = configuration.jwt;
//构建token
exports.createToken = function (user) {
  const token = jwt.sign({ user }, secret, { expiresIn });
  return token;
};
//验证token
exports.vertifyToken = function (token) {
  try {
    var decoded = jwt.verify(token, secret);
  } catch (err) {
    return false;
  } finally {
    return decoded;
  }
};
//解密token
exports.decryptToken = (token) => {
  let decoded = null;
  try {
    decoded = jwt.decode(token, secret);
  } catch (error) {
  } finally {
    return decoded;
  }
};
